<template>
  <div class="app-header-sticky" :class="{show:y>=78}">
    <div class="container" v-show="y>=78">
      <router-link class="logo" to="/"></router-link>
      <app-header-nav></app-header-nav>
      <div class="right">
        <router-link to="/">品牌</router-link>
        <router-link to="/">专题</router-link>
      </div>
    </div>
  </div>
</template>

<script>
import appHeaderNav from './app-header-nav.vue'
import { onMounted, ref } from 'vue'
export default {
  components: { appHeaderNav },
  name: 'AppHeaderSticky',
  setup () {
    // 记录y轴卷曲高度
    const y = ref(0)
    // 当页面滚动之后更新
    onMounted(() => {
      window.onscroll = () => {
        const scrollTop = document.documentElement.scrollTop
        // 修改ref的值时候 需要加上.value
        // console.log(scrollTop)
        y.value = scrollTop
      }
    })
    // 将y值提供给模板使用
    return { y }
  }
}
</script>

<style lang="less" scoped>
.app-header-sticky{
  width: 100%;
  height: 80px;
  position: fixed;
  left: 0;
  top:0;
  // 优先级别
  z-index:999;
  background-color: #fff;
  border-bottom: 1px solid #e4e4e4;
  transform: translateY(-100%);
  opacity: 0;
  &.show{
    transform: none;
    opacity: 1;
    transition: all 0.4s linear;
  }
  .container{
    display:flex;
    align-items: center;
  }
  .logo{
    width: 200px;
    height: 80px;
    background: url(../assets/images/logo.png) no-repeat right 2px;
    background-size: 200px auto;
  }
  .right{
    width: 220px;
    display: flex;
    text-align: left;
    // padding-left: 10px;
    border-left: 2px solid @xtxColor;
    a {
      width: 38px;
      margin-left: 40px;
      font-size: 16px;
      line-height: 1;
      &:hover{
        color: @xtxColor;
      }
    }
  }
}
</style>
